﻿using HeSeHus.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HeSeHus
{
    /// <summary>
    /// Interaction logic for connectionString.xaml
    /// </summary>
    public partial class connectionString : Window
    {
        private bool _isNative;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="isNative">Tilstands flag:<para>True: Native settings</para><para>False: Produktions settings</para></param>
        public connectionString(bool isNative)
        {
            _isNative = isNative;
            InitializeComponent();
            if (_isNative)
            {
                Title = "Rediger Connection string Native";
                txtIpAdresse.Text = Settings.Default["NativeDatabase"].ToString();
                txtDatabaseNavn.Text = Settings.Default["NativeCatalog"].ToString();
                txtUser.Text = Settings.Default["NativeUser"].ToString();
                ptxtPass.Password = Settings.Default["NativePassword"].ToString();
            }
            else
            {

                Title = "Rediger Connection string Produktion";
                txtIpAdresse.Text = Settings.Default["ProdDatabase"].ToString();
                txtDatabaseNavn.Text = Settings.Default["ProdCatalog"].ToString();
                txtUser.Text = Settings.Default["ProdUser"].ToString();
                ptxtPass.Password = Settings.Default["ProdPassword"].ToString();
            }
        }

        
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (_isNative)
            {
                Settings.Default["NativeDatabase"] = txtIpAdresse.Text;
                Settings.Default["NativeCatalog"] = txtDatabaseNavn.Text;
                Settings.Default["NativeUser"] = txtUser.Text;
                Settings.Default["NativePassword"] = ptxtPass.Password;
                Settings.Default["NativeConString"] = "server=" + Settings.Default["NativeDatabase"] + "; initial catalog=" + Settings.Default["NativeCatalog"] + "; user=" + Settings.Default["NativeUser"] + "; password=" + Settings.Default["NativePassword"] + ";";
                Settings.Default.Save();
            }
            else
            {
                Settings.Default["ProdDatabase"] = txtIpAdresse.Text;
                Settings.Default["ProdCatalog"] = txtDatabaseNavn.Text;
                Settings.Default["ProdUser"] = txtUser.Text;
                Settings.Default["ProdPassword"] = ptxtPass.Password;
                Settings.Default["ProductionConString"] = "server=" + Settings.Default["ProdDatabase"] + "; initial catalog=" + Settings.Default["ProdCatalog"] + "; user=" + Settings.Default["ProdUser"] + "; password=" + Settings.Default["ProdPassword"] + ";";
                Settings.Default.Save();
            }
            this.Close();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
